package com.example.senior_homework.di

import android.content.Context
import androidx.room.Room
import com.example.senior_homework.repository.dao.SeniorDao
import com.example.senior_homework.repository.db.SeniorDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
class DbModule {


    @Provides
    fun provideDatabase(@ApplicationContext applicationContext: Context):SeniorDatabase{
        return Room.databaseBuilder(
            applicationContext,
            SeniorDatabase::class.java,
            "senior_database"
        ).build()
    }

//    @ApplicationContext 是一个Hilt提供的注解，用于指定注入的Context是应用上下文（Application Context）(因为Context可能多个)

    @Provides
    fun provideSeniorDao(database: SeniorDatabase): SeniorDao {
        return database.seniorDao()
    }
}